<?php

namespace Home\Model;

use Think\Model;

class ArticleModel extends Model
{
    protected $tableName = "article";
    protected $_validate = array(
        array('title','require','请填写标题！'),
        array('title','','此标题已经存在,请不要重复添加！',1,'unique',1),
        array('type','require','请选择类型！'),
        array('author','require','请填写作者！'),
        array('keywords','require','请填写关键描述！'),
        array('content','require','请填写关内容！！'),
        array('pic','require','图片必须上传'),
    );


    /* author@zhou
     * 功能 判断sortid 是否存在
     * return 
     */
    public function check_sortid($sortid)
    {
        $row = $this->where("sortid = $sortid")->find();
        if (is_null($row)) {
            return false;
        }
        return true;
    }

    /* author@zhou
     * 功能 新增
     * return
     */
    public function insert($data = array())
    {
        return $this->add($data);
    }

    public function getAllByLimit($opt, $page, $pageSize)
    {
        $data = $this->where($opt)->page($page, $pageSize)->select();
        $count = $this->where($opt)->count();
        return array('data' => $data, 'count' => $count);

    }
}